import 'package:enter_prise_web/page/index/index_controller.dart';
import 'package:enter_prise_web/page/work/work_controller.dart';
import 'package:enter_prise_web/page/work/work_page.dart';
import 'package:enter_prise_web/widgets/side_menu_item.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';

import '../common/constants.dart';

class SideMenu extends StatelessWidget {
  SideMenu({super.key});
  final IndexController indexController = Get.find();
  final WorkController workController = Get.find();
  @override
  Widget build(BuildContext context) {
    return Container(
        height: double.infinity,
        color: kDefaualtBgColor,
        padding: const EdgeInsets.only(top: kIsWeb ? kDefaultPadding : 0),
        child: SafeArea(
          child: SingleChildScrollView(
            padding: const EdgeInsets.symmetric(horizontal: kDefaultPadding),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Row(
                  children: [
                    SvgPicture.asset(
                      "assets/logo.svg",
                      width: 80,
                      height: 80,
                    ),
                    const Spacer(),
                    const CloseButton(),
                  ],
                ),
                const Divider(
                  color: kGrayColor,
                ),
                SideMenuItem(
                  const ["主页", "工件", "员工", "记录", "更多"],
                  const [
                    Icons.home,
                    IconFont.icon_wrench,
                    IconFont.icon_yuangongguanli,
                    Icons.note,
                    IconFont.icon_gengduo
                  ],
                  onPress: (index, String title) {
                    NavigatorPage(
                        index: index,
                        title: title,
                        indexController: indexController,
                        workController: workController);
                  },
                ),
              ],
            ),
          ),
        ));
  }
}

NavigatorPage(
    {WorkController? workController,
    IndexController? indexController,
    int? index,
    bool? isSingle = false,
    String? uid,
    String? title}) {
  if (index == 3 && isSingle == false && workController!.isSingle.value) {
    workController.isSingle.value = false;
    workController.updateData(FilterType.week);
  }

  if (index == 3 && isSingle == true) {
    workController!.isSingle.value = true;

    workController.updateData(FilterType.week);
  }
  indexController!.currentIndex.value = index!;
  indexController.title.value = title!;

  indexController.pageController.animateToPage(index,
      duration: const Duration(microseconds: 2000), curve: Curves.ease);
}
